package com.hospital.hospitalsystem.modules.base.controller;

import com.hospital.hospitalsystem.base.BaseResponse;
import com.hospital.hospitalsystem.config.TokenVerify;
import com.hospital.hospitalsystem.modules.base.biz.UploadBiz;
import com.hospital.hospitalsystem.modules.base.dto.DeleteReq;
import com.hospital.hospitalsystem.modules.base.dto.UploadRsp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author qiancheng@cqxyy.net
 * @date 2022/11/7
 */
@RestController
@RequestMapping("/upload")
@Api(tags = "上传时需调用的接口")
@Validated
public class UploadController {
    @Autowired
    private UploadBiz upload;

    @ApiOperation(value = "上传图片到minio")
    @RequestMapping(path = "/picture",method = RequestMethod.POST)
    public BaseResponse<UploadRsp> upload(@RequestParam("file") MultipartFile file,@RequestParam("bucketName")String bucketName){
        UploadRsp result = upload.upload(file,bucketName);
        return BaseResponse.success(result);
    }

    @ApiOperation(value = "删除")
    @RequestMapping(path = "/picture/delete",method = RequestMethod.POST)
    public BaseResponse delete(@RequestBody DeleteReq deleteReq){
        upload.delete(deleteReq);
        return BaseResponse.success();
    }
}
